#include "include.h"
#include "port_lcd.h"
#if (GUI_SELECT == GUI_LCD_5110)
u8 lcd_buf[LINE_MAX * COLUMN_MAX] AT(.buf.lcd);
u8 freq_spectrum_buf[16] AT(.buf.lcd);
AT(.text.lcd.table)
const u8 tbl_freq_spectrum0[15] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe};
AT(.text.lcd.table)
const u8 tbl_freq_spectrum1[15] = {0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
//取码规则:	低位在前, 列行扫描, 阴码(1-亮, 0-灭)
//查表方法: 要显示的ASCII码-32就可以得到字库码的指针
AT(.text.lcd.table)
const unsigned char  Font_code[][16] = {
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},// 0
{0x00,0x00,0x70,0xF8,0xF8,0x70,0x00,0x00,0x00,0x00,0x00,0x0D,0x0D,0x00,0x00,0x00},//!1
{0x00,0x38,0x38,0x00,0x00,0x38,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},//"2
{0x00,0x20,0xF8,0xF8,0x20,0xF8,0xF8,0x20,0x00,0x02,0x0F,0x0F,0x02,0x0F,0x0F,0x02},//#3
{0x00,0x30,0x78,0xCE,0x8E,0x18,0x10,0x00,0x00,0x04,0x0C,0x38,0x39,0x0F,0x06,0x00},//$4
{0x18,0x3C,0x24,0xBC,0xD8,0x60,0x30,0x00,0x00,0x06,0x03,0x0D,0x1E,0x12,0x1E,0x0C},//%5
{0x00,0xB0,0xF8,0x48,0x78,0x30,0x00,0x00,0x00,0x07,0x0F,0x08,0x09,0x07,0x0F,0x09},//&6
{0x00,0x00,0x00,0x38,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},//'7
{0x00,0x00,0xC0,0xF0,0x38,0x08,0x00,0x00,0x00,0x00,0x07,0x1F,0x38,0x20,0x00,0x00},//(8
{0x00,0x00,0x08,0x38,0xF0,0xC0,0x00,0x00,0x00,0x00,0x20,0x38,0x1F,0x07,0x00,0x00},//)9
{0x00,0x80,0xA0,0xE0,0xC0,0xE0,0xA0,0x80,0x00,0x00,0x02,0x03,0x01,0x03,0x02,0x00},//*10
{0x00,0x80,0x80,0xE0,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x03,0x03,0x00,0x00,0x00},//+11
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x2C,0x3C,0x1C,0x00,0x00},//,12
{0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},//-13
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x0C,0x0C,0x00,0x00},//.14
{0x00,0x00,0x00,0x80,0xE0,0x78,0x18,0x00,0x00,0x18,0x1E,0x07,0x01,0x00,0x00,0x00},///15
{0x00,0x00,0xF0,0xF8,0x08,0x68,0xF8,0xF0,0x00,0x00,0x07,0x0F,0x0B,0x08,0x0F,0x07},//016
{0x00,0x20,0x20,0x30,0xF8,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x0F,0x00,0x00},//117
{0x00,0x30,0x38,0x08,0x88,0xF8,0x70,0x00,0x00,0x0C,0x0E,0x0B,0x09,0x08,0x08,0x00},//218
{0x00,0x30,0x38,0x88,0x88,0xF8,0x70,0x00,0x00,0x06,0x0E,0x08,0x08,0x0F,0x07,0x00},//319
{0x00,0x00,0xF8,0xF8,0x00,0xE0,0xE0,0x00,0x00,0x03,0x03,0x02,0x02,0x0F,0x0F,0x02},//420
{0x00,0xF8,0xF8,0x88,0x88,0x88,0x08,0x00,0x00,0x08,0x08,0x08,0x0C,0x07,0x03,0x00},//521
{0x00,0xC0,0xE0,0x78,0x58,0xC8,0x80,0x00,0x00,0x07,0x0F,0x08,0x08,0x0F,0x07,0x00},//622
{0x00,0x08,0x08,0x88,0xE8,0x78,0x18,0x00,0x00,0x00,0x0E,0x0F,0x01,0x00,0x00,0x00},//723
{0x00,0x70,0xF8,0xC8,0x88,0xF8,0x70,0x00,0x00,0x07,0x0F,0x08,0x09,0x0F,0x07,0x00},//824
{0x00,0xF0,0xF8,0x08,0x08,0xF8,0xF0,0x00,0x00,0x00,0x09,0x0D,0x0F,0x03,0x01,0x00},//925
{0x00,0x00,0x00,0x60,0x60,0x60,0x00,0x00,0x00,0x00,0x00,0x0C,0x0C,0x0C,0x00,0x00},//:26
{0x00,0x00,0x00,0x60,0x60,0x60,0x00,0x00,0x00,0x00,0x00,0x2C,0x3C,0x1C,0x00,0x00},//;27
{0x00,0x80,0xC0,0x60,0x30,0x18,0x08,0x00,0x00,0x00,0x01,0x03,0x06,0x0C,0x08,0x00},//<28
{0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x00},//=29
{0x00,0x08,0x18,0x30,0x60,0xC0,0x80,0x00,0x00,0x08,0x0C,0x06,0x03,0x01,0x00,0x00},//>30
{0x00,0x30,0x38,0x88,0xC8,0x78,0x30,0x00,0x00,0x00,0x00,0x0D,0x0D,0x00,0x00,0x00},//?31
{0xF0,0xF8,0x08,0x88,0xC8,0x48,0xF8,0xF0,0x07,0x0F,0x08,0x09,0x0B,0x0A,0x0B,0x0B},//@32
{0x00,0xE0,0xF0,0x18,0x18,0xF0,0xE0,0x00,0x00,0x0F,0x0F,0x01,0x01,0x0F,0x0F,0x00},//A33
{0x00,0xF8,0xF8,0x88,0x88,0xF8,0x70,0x00,0x00,0x0F,0x0F,0x08,0x08,0x0F,0x07,0x00},//B34
{0x00,0xF0,0xF8,0x08,0x08,0x38,0x30,0x00,0x00,0x07,0x0F,0x08,0x08,0x0E,0x06,0x00},//C35
{0x00,0xF8,0xF8,0x08,0x18,0xF0,0xE0,0x00,0x00,0x0F,0x0F,0x08,0x0C,0x07,0x03,0x00},//D36
{0x00,0xF8,0xF8,0x88,0x88,0x88,0x08,0x00,0x00,0x0F,0x0F,0x08,0x08,0x08,0x08,0x00},//E37
{0x00,0xF8,0xF8,0x88,0x88,0x88,0x08,0x00,0x00,0x0F,0x0F,0x00,0x00,0x00,0x00,0x00},//F38
{0x00,0xF0,0xF8,0x08,0x08,0x38,0x30,0x00,0x00,0x07,0x0F,0x08,0x09,0x0F,0x0F,0x00},//G39
{0x00,0xF8,0xF8,0x80,0x80,0xF8,0xF8,0x00,0x00,0x0F,0x0F,0x00,0x00,0x0F,0x0F,0x00},//H40
{0x00,0x00,0x08,0xF8,0xF8,0x08,0x00,0x00,0x00,0x00,0x08,0x0F,0x0F,0x08,0x00,0x00},//I41
{0x00,0x00,0x00,0x00,0x00,0xF8,0xF8,0x00,0x00,0x06,0x0E,0x08,0x08,0x0F,0x07,0x00},//J42
{0x00,0xF8,0xF8,0x80,0xE0,0x78,0x18,0x00,0x00,0x0F,0x0F,0x00,0x03,0x0F,0x0C,0x00},//K43
{0x00,0xF8,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x0F,0x08,0x08,0x08,0x08,0x00},//L44
{0x00,0xF8,0xF8,0x20,0xC0,0x20,0xF8,0xF8,0x00,0x0F,0x0F,0x00,0x01,0x00,0x0F,0x0F},//M45
{0x00,0xF8,0xF8,0x60,0xC0,0x80,0xF8,0xF8,0x00,0x0F,0x0F,0x00,0x00,0x01,0x0F,0x0F},//N46
{0x00,0xF0,0xF8,0x08,0x08,0xF8,0xF0,0x00,0x00,0x07,0x0F,0x08,0x08,0x0F,0x07,0x00},//O47
{0x00,0xF8,0xF8,0x88,0x88,0xF8,0x70,0x00,0x00,0x0F,0x0F,0x00,0x00,0x00,0x00,0x00},//P48
{0x00,0xF0,0xF8,0x08,0x08,0xF8,0xF0,0x00,0x00,0x07,0x0F,0x08,0x18,0x3F,0x27,0x00},//Q49
{0x00,0xF8,0xF8,0x88,0x88,0xF8,0x70,0x00,0x00,0x0F,0x0F,0x00,0x01,0x0F,0x0E,0x00},//R50
{0x00,0x30,0x78,0xC8,0x88,0x18,0x10,0x00,0x00,0x04,0x0C,0x08,0x09,0x0F,0x06,0x00},//S51
{0x00,0x08,0x08,0xF8,0xF8,0x08,0x08,0x00,0x00,0x00,0x00,0x0F,0x0F,0x00,0x00,0x00},//T52
{0x00,0xF8,0xF8,0x00,0x00,0xF8,0xF8,0x00,0x00,0x07,0x0F,0x08,0x08,0x0F,0x07,0x00},//U53
{0x00,0xF8,0xF8,0x00,0x00,0xF8,0xF8,0x00,0x00,0x03,0x07,0x0C,0x0C,0x07,0x03,0x00},//V54
{0x00,0xF8,0xF8,0x00,0xC0,0x00,0xF8,0xF8,0x00,0x01,0x0F,0x0E,0x01,0x0E,0x0F,0x01},//W55
{0x00,0x18,0x38,0xE0,0xC0,0x38,0x18,0x00,0x00,0x0E,0x0F,0x00,0x01,0x0F,0x0E,0x00},//X56
{0x00,0x78,0xF8,0x80,0x80,0xF8,0x78,0x00,0x00,0x00,0x00,0x0F,0x0F,0x00,0x00,0x00},//Y57
{0x00,0x08,0x08,0x88,0xC8,0x78,0x38,0x00,0x00,0x0E,0x0F,0x09,0x08,0x08,0x08,0x00},//Z58
{0x00,0x00,0xF8,0xF8,0x08,0x08,0x00,0x00,0x00,0x00,0x7F,0x7F,0x40,0x40,0x00,0x00},//[59
{0x00,0x18,0x78,0xE0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x07,0x1E,0x18,0x00},//\60
{0x00,0x00,0x08,0x08,0xF8,0xF8,0x00,0x00,0x00,0x00,0x40,0x40,0x7F,0x7F,0x00,0x00},//]61
{0x00,0x08,0x0C,0x06,0x06,0x0C,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},//^62
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40},//_63
{0x00,0x00,0x02,0x06,0x0E,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},//`64
{0x00,0x00,0x20,0x20,0x20,0xE0,0xC0,0x00,0x00,0x06,0x0F,0x09,0x09,0x0F,0x0F,0x00},//a65
{0x00,0xF8,0xF8,0x20,0x20,0xE0,0xC0,0x00,0x00,0x0F,0x0F,0x08,0x08,0x0F,0x07,0x00},//b66
{0x00,0xC0,0xE0,0x20,0x20,0x60,0x40,0x00,0x00,0x07,0x0F,0x08,0x08,0x0C,0x04,0x00},//c67
{0x00,0xC0,0xE0,0x20,0x20,0xF8,0xF8,0x00,0x00,0x07,0x0F,0x08,0x08,0x0F,0x0F,0x00},//d68
{0x00,0xC0,0xE0,0x20,0x20,0xE0,0xC0,0x00,0x00,0x07,0x0F,0x09,0x09,0x09,0x01,0x00},//e69
{0x00,0x80,0xF0,0xF8,0x88,0x88,0x88,0x00,0x00,0x00,0x0F,0x0F,0x00,0x00,0x00,0x00},//f70
{0x00,0xC0,0xE0,0x20,0x20,0xE0,0xE0,0x00,0x00,0x47,0x4F,0x48,0x48,0x7F,0x3F,0x00},//g71
{0x00,0xF8,0xF8,0x20,0x20,0xE0,0xC0,0x00,0x00,0x0F,0x0F,0x00,0x00,0x0F,0x0F,0x00},//h72
{0x00,0x20,0x20,0xEC,0xEC,0x00,0x00,0x00,0x00,0x08,0x08,0x0F,0x0F,0x08,0x08,0x00},//i73
{0x00,0x00,0x20,0x20,0xEC,0xEC,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x3F,0x00,0x00},//j74
{0x00,0xF8,0xF8,0x00,0x80,0xE0,0x60,0x00,0x00,0x0F,0x0F,0x01,0x03,0x0E,0x0C,0x00},//k75
{0x00,0x08,0x08,0xF8,0xF8,0x00,0x00,0x00,0x00,0x08,0x08,0x0F,0x0F,0x08,0x08,0x00},//l76
{0x00,0xE0,0xE0,0x20,0xE0,0x20,0xE0,0xC0,0x00,0x0F,0x0F,0x00,0x07,0x00,0x0F,0x0F},//m77
{0x00,0xE0,0xE0,0x20,0x20,0xE0,0xC0,0x00,0x00,0x0F,0x0F,0x00,0x00,0x0F,0x0F,0x00},//n78
{0x00,0xC0,0xE0,0x20,0x20,0xE0,0xC0,0x00,0x00,0x07,0x0F,0x08,0x08,0x0F,0x07,0x00},//o79
{0x00,0xE0,0xE0,0x20,0x20,0xE0,0xC0,0x00,0x00,0x7F,0x7F,0x08,0x08,0x0F,0x07,0x00},//p80
{0x00,0xC0,0xE0,0x20,0x20,0xE0,0xE0,0x00,0x00,0x07,0x0F,0x08,0x08,0x7F,0x7F,0x00},//q81
{0x00,0xE0,0xE0,0x80,0x40,0x60,0x60,0x00,0x00,0x0F,0x0F,0x00,0x00,0x00,0x00,0x00},//r82
{0x00,0xC0,0xE0,0x20,0x20,0x20,0x20,0x00,0x00,0x08,0x09,0x09,0x09,0x0F,0x06,0x00},//s83
{0x00,0x20,0xF8,0xF8,0x20,0x20,0x20,0x00,0x00,0x00,0x07,0x0F,0x08,0x08,0x08,0x00},//t84
{0x00,0xE0,0xE0,0x00,0x00,0xE0,0xE0,0x00,0x00,0x07,0x0F,0x08,0x08,0x0F,0x0F,0x00},//u85
{0x00,0xE0,0xE0,0x00,0x00,0xE0,0xE0,0x00,0x00,0x03,0x07,0x0C,0x0C,0x07,0x03,0x00},//v86
{0x00,0xE0,0xE0,0x00,0xC0,0x00,0xE0,0xE0,0x00,0x03,0x0F,0x0C,0x03,0x0C,0x0F,0x03},//w87
{0x00,0x60,0xE0,0x80,0x80,0xE0,0x60,0x00,0x00,0x0C,0x0E,0x03,0x03,0x0E,0x0C,0x00},//x88
{0x00,0xE0,0xE0,0x00,0x00,0xE0,0xE0,0x00,0x40,0x47,0x4F,0x68,0x38,0x1F,0x07,0x00},//y89
{0x00,0x20,0x20,0x20,0xA0,0xE0,0x60,0x00,0x00,0x0C,0x0E,0x0B,0x09,0x08,0x08,0x00},//z90
{0x00,0x00,0x80,0xF0,0x78,0x08,0x00,0x00,0x00,0x01,0x03,0x1E,0x3C,0x20,0x00,0x00},//{91
{0x00,0x00,0x00,0xF8,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x7F,0x00,0x00,0x00},//|92
{0x00,0x00,0x08,0x78,0xF0,0x80,0x00,0x00,0x00,0x00,0x20,0x3C,0x1E,0x03,0x01,0x00},//}93
{0x30,0x18,0x08,0x18,0x30,0x20,0x30,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}};//~94

///SPI接口发送1Byte数据
AT(.text.lcd)
static void spi1_sendbyte(u8 data)
{
    SPI1CON &= ~BIT(4);                                 //TX
    SPI1BUF = data;
    while (!(SPI1CON & BIT(16)));                       //Wait pending
}

/****************************************************
描    述: 更新屏显示
入口参数: x: 0 - 83(列位置), y: 0 - 5(行位置)
出口参数: 无
****************************************************/
AT(.text.lcd)
void lcd_screen_update(u8 x, u8 y, u8 *buf, u16 len)
{
    if (y >= LINE_MAX) {
        return;
    }
    LCD_CMD_EN();
    LCD_SPI_CS_EN();
    x |= X_Col_Addr;
	y |= Y_Page_Addr;
	spi1_sendbyte(x);	//列地址
	spi1_sendbyte(y);	//页地址
    //spi1_sendbyte(LCD_COLUMN_HIGH | (x >> 4));
    //spi1_sendbyte(LCD_COLUMN_LOW  | (x & 0x0f));
    //spi1_sendbyte(LCD_PAGE_ADDR   |  y);
    LCD_SPI_CS_DIS();
    LCD_CMD_DIS();
    asm("nop"); asm("nop");

    LCD_SPI_CS_EN();
    SPI1DMAADR = DMA_ADR(buf);
    SPI1DMACNT = len;
	while (!(SPI1CON & BIT(16)));                       //waiting finish pending
/*    for (u16 i = 0; i < len; i++) {
        spi1_sendbyte(buf[i]);
    }*/
    LCD_SPI_CS_DIS();
}


/*
///设置LCD屏的对比度
AT(.text.lcd)
void lcd_set_contrast(u8 val)
{
    if (val > 15) {
        val = 15;
    }
    lcd_spi_send_cmd(LCD_ELE_VOLUME);                   //electronic Volume
    lcd_spi_send_cmd(val);
}
*/
AT(.text.lcd)
void lcd_spi_send_cmd(u8 cmd)
{
    LCD_CMD_EN();
    LCD_SPI_CS_EN();
    spi1_sendbyte(cmd);
    LCD_SPI_CS_DIS();
    LCD_CMD_DIS();
}
/*
AT(.text.lcd)
void lcd_screen_clear(void)
{
    memset(lcd_buf, 0, sizeof(lcd_buf));
    for (u8 i = 0; i != 8; i++) {
        lcd_screen_update(0, i, &lcd_buf[i*COLUMN_MAX], COLUMN_MAX);
    }
}*/
AT(.text.lcd)
void lcd_screen_set(u8 dat)
{
    memset(lcd_buf, dat, sizeof(lcd_buf));
    for (u8 i = 0; i < LINE_MAX; i++) {
        lcd_screen_update(0, i, &lcd_buf[i*COLUMN_MAX], COLUMN_MAX);
    }
}

AT(.text.lcd)
void lcd_buf_clear(void)
{
    memset(lcd_buf, 0, sizeof(lcd_buf));
}

AT(.text.lcd)
void lcd_line_clear(u16 y)
{
    memset(&lcd_buf[y*COLUMN_MAX], 0, COLUMN_MAX);
}
/*--------------------------------------------------------------*/
//液晶字节定位(1*1)
//液晶规划:
//x: 0 - 83
//y: 0 - 5

/*--------------------------------------------------------------*/
//液晶字符输出(8*16字体)
//x: 0 - 9
//y: 0 - 2
AT(.text.lcd)
void LCD_printc(unsigned char x, unsigned char y, unsigned char c_dat)
{
	//unsigned char i, j;
    unsigned char *p;
	c_dat -= 32;
	x <<= 3;		//8,对于8*16字体，每个字符占用像素为8，比如位置写入x=2，对应的像素点起始位置=2*8=16
	y <<= 1;		//16，竖方向48像素点分为6个地址[0-5]，对于8*16字体，竖向占用16个像素点
	//for(j = 0; j < 2; j++)	{
		//LCD_pos_byte(x, (y + j));
		//for(i = 0; i < 8; i++)
			//LCD_write_dat(Font_code[c_dat][8 * j + i]);
			p = lcd_buf+y*COLUMN_MAX+x	;
			memcpy(p,&(Font_code[c_dat][0 ]),8);
			lcd_screen_update(x,y,p,8);
			p+= COLUMN_MAX;
			memcpy(p,&(Font_code[c_dat][8 ]),8);
			lcd_screen_update(x,y+1,p,8);
	//}
}
/*--------------------------------------------------------------*/
//液晶字符串输出(8*16字体)
//x: 0 - 9
//y: 0 - 2
AT(.text.lcd)
void LCD_prints(unsigned char x, unsigned char y,  char  *s_dat)
{
	while(*s_dat && x < 10)
	{LCD_printc(x++, y, *s_dat); s_dat++;}
}

//AT(.text.lcd.init)
AT(.text.lcd)
void lcd_init(void)
{
    printf("%s\n", __func__);
    //memset(&nmv_cb, 0, sizeof(nmv_cb));
    lcd_spi_init();
    /*
    lcd_spi_send_cmd(0x40);                             //start line 0
    lcd_spi_send_cmd(LCD_BIAS_SET | 0x00);              //lcd bias setting
    lcd_spi_send_cmd(LCD_ADC_SEL);                      //invert display 0 or 1
    lcd_spi_send_cmd(LCD_COMMON_MODE & 0xc8);           //common output mode
    lcd_spi_send_cmd(LCD_V0_RATIO | 0x06);              //Resistor Ratio
    lcd_set_contrast(LCD_CONTRAST_DEFAULT);             //设置对比度
    lcd_spi_send_cmd(LCD_POWER_MODE);                   //lcd power control
    lcd_spi_send_cmd(LCD_ON);
*/
	lcd_spi_send_cmd(0x21);		//工作模式, 水平寻址, 扩展指令
	lcd_spi_send_cmd(0x06);		//VLCD温度系数2
	lcd_spi_send_cmd(0x13);		//设置偏置系统(BSx) 1:48
	lcd_spi_send_cmd(0xc8);		//设置电压VLCD = 3.06 + 0.06*Vop, 对比度调整
	lcd_spi_send_cmd(0x20);		//工作模式, 水平寻址, 常规指令
	lcd_spi_send_cmd(0x0c);		//普通模式
	lcd_spi_send_cmd(Y_Page_Addr);	//起始页地址0
	lcd_spi_send_cmd(X_Col_Addr);	//起始列地址0
    u8 dat = 1;
	for(int i=0;i<100;i++){
        lcd_screen_set(dat);
        delay_5ms(20);
        dat <<=1;
        if(dat == 0)    dat = 1;
	}

	LCD_prints(3, 2, "(*^_^*)");
	delay_5ms(100);
	LCD_prints(0, 1, "AD=");
	delay_5ms(100);
	LCD_prints(0, 0, "T =");
	delay_5ms(100);
}
#endif

#if ((GUI_SELECT == GUI_LCD)||(GUI_SELECT == GUI_LCD_5110))
AT(.text.lcd.port)
void lcd_spi_init(void)
{
    LCD_CMD_INIT();
    LCD_SPI_CS_INIT();
    LCD_SPI_CLK_INIT();
    LCD_SPI_DAT_INIT();
    LCD_RST_INIT();
    delay_us(50);
    LCD_RST_CLR();                              //LCD reset
    delay_us(300);
    LCD_RST_SET();
    delay_us(20);
    LCD_BACKLIGHT_INIT();

    FUNCMCON1 = SPI1MAP_G;
    SPI1CON = BIT(5) | BIT(2) | BIT(0);          //2 WIRE, IDLE 1, EN, NORMAL , dis irq
    SPI1BAUD = 0x01;
}
#endif
